<?php
// +----------------------------------------------------------------------
// | MC PHP[基于ThinkPHP6.1开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2023 http://www.mingchangruanjian.com
// +----------------------------------------------------------------------
// | Author jokerfei [ jokerfei377@gmail.com ]
// +----------------------------------------------------------------------
// | 铭畅软件 技术部 出品
// +----------------------------------------------------------------------
namespace app\api\controller\v1;

use app\api\controller\Base;
use app\common\service\ApiReturn;
use AppendIterator;

class News extends Base
{
    /** 
     * @Author: Bryant  
     * @Date: 2025-02-15 08:40:37 
     * @method post 
     * @title 获取分类 
     */
    public function videoInfo($data,$user)
    {
        $info = \app\admin\model\News::where('id',$data['id'])->find();
        return ApiReturn::r(1,$info,'ok');
    }
    /** 
     * @Author: Bryant  
     * @Date: 2025-02-08 11:18:26 
     * @method post 
     * 【探数API】新闻查询-头条新闻-新闻资讯-娱乐新闻-体育新闻-科技新闻-国际新闻
     * @title https://market.aliyun.com/apimarket/detail/cmapi00065872?spm=5176.730005.result.6.252b414aDTByQY&innerSource=search_%E6%96%B0%E9%97%BB%E8%B5%84%E8%AE%AF#sku=yuncode5987200003
     */
    public function toutiao($data)
    {
        if($data['channel'] == '科技1'){
            $list  = \app\admin\model\News::where('type',1)->field('id,image as pic,title,time')->select();
            return ApiReturn::r(1,[
                'list' => $list,
                'is_open' => 0
            ],'ok');
        }else{
            $host = "https://tstoutiao.market.alicloudapi.com";
            $path = "/toutiao/index";
            $method = "GET";
            $appcode = "4d21abd7f21d40d4b61de26d0fef8449";
            $headers = array();
            array_push($headers, "Authorization:APPCODE " . $appcode);
            $querys = "type=".urlencode($data['channel'])."&num=10&start=".$data['start'];
            $bodys = "";
            $url = $host . $path . "?" . $querys;

            $curl = curl_init();
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($curl, CURLOPT_FAILONERROR, false);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_HEADER, false);
            if (1 == strpos("$".$host, "https://"))
            {
                curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            }
            $res = curl_exec($curl);
            $res = json_decode($res,true);
            $arr = [];
            $list = $res['data']['list'];
            foreach($list as $v){
                if (strpos($v['title'], "彩") !== false) {
                   
                }else{
                    $arr[] = $v;
                }
            }
            $res['data']['list'] = $arr;
            $is_open = 0;
            return ApiReturn::r(1,[
                'list' => $res['data']['list'],
                'is_open' => $is_open
            ],'ok');
        }
        
    }
    /** 
     * @Author: Bryant  
     * @Date: 2025-04-22 17:51:47 
     * @method post 
     * @title 获取新闻详情 
     */
    public function getNewsInfo($data,$user)
    {
        $info = \app\admin\model\News::where('id',$data['id'])->find();
        return ApiReturn::r(1,$info,'ok');
    }
}
